
<div id='MainStore_Page'>
	<h2 style='text-align:center'>商户审核</h2>
	<div style='display:flex'>
		<div style='flex:1'>
			<input type="text" id='MainStore_SearchInp' style='width:100%' />
		</div>
		<div>
			<button type='button' id='MainStore_SearchBtn'>搜索</button>
		</div>
	</div>
	<select id="MainStore_TypeSelect" style='width:100%'>
		<option value="5">全部</option>
		<option value="1">待审核</option>
		<option value="2">正常</option>
		<option value="3">未通过</option>
		<option value="4">已封禁</option>
	</select>

	<div id='MainStore_StoreList'></div>

	<div id='AdminStoreContorl_Fpage' style='text-align:center;margin:20px auto'></div>
</div>

<div id='MainStore_StoreGoodsList'></div>

<script>
	//初始始化商户列表当前页
	if(!sessionStorage.MainStore_Pnow){
		sessionStorage.MainStore_Pnow = 1;
	}

	//最大页
	if(!sessionStorage.MainStore_MaxPage){
		sessionStorage.MainStore_MaxPage = sessionStorage.MainStore_Pnow + 1;
	}

	//初始始化商户搜索值
	if(!sessionStorage.MainStore_Search){
		sessionStorage.MainStore_Search = '';
	}else{
		$('#MainStore_SearchInp').val(ChangeChar(sessionStorage.MainStore_Search,1));
	}

	//状态维持
	if(sessionStorage.MainStore_statType){
		$('#MainStore_TypeSelect').val(sessionStorage.MainStore_statType);
	}


	//点击搜索
	$('#MainStore_SearchBtn').click(function(){
		$('#MainStore_StoreList').html('');
		$('#AdminStoreContorl_Fpage').html('');
		_MainStore_Reset();		//重置本页相关数据
		sessionStorage.MainStore_Search = ChangeChar($('#MainStore_SearchInp').val().trim());
		MainStore_GetAndView();
	});


	//状态类别选择
	$('#MainStore_TypeSelect').change(function(){
		sessionStorage.MainStore_statType = $('#MainStore_TypeSelect').find('option:selected').val();
		$('#MainStore_StoreList').html('');
		$('#AdminStoreContorl_Fpage').html('');
		_MainStore_Reset();		//重置本页相关数据
		MainStore_GetAndView();

	});


	MainStore_GetAndView();

	function MainStore_GetAndView(){	
		MainStore_GetStoreList(function(storeList){
			MainStore_GetStoreList_Parse(storeList);
		});
	}




	//获取商户列表并显示
	function MainStore_GetStoreList(fun){
		//Notice('加载中.....');
		var data ={
			type:'getStoreList',
			stat_type:sessionStorage.MainStore_statType,
			pnow:sessionStorage.MainStore_Pnow,
			search:sessionStorage.MainStore_Search
		}
		AjaxAdmin(data,function(res){
			C(res);
			var tmp = _checkJsonFormat(res);
			fun(tmp.data);
		});
	}





	function MainStore_GetStoreList_Parse(tmp_data){
		//Notice('');
		if(typeof(tmp_data) == 'object' && tmp_data.length > 0){
			var tmp_str = '';
			for(var i=0;i<tmp_data.length;i++){
				tmp_str += "<div style='margin:5px 0;border:1px solid;word-break:break-all;font-size:14px;color:#777;padding:5px'>";
				if(tmp_data[i].banner){
					var tmp_img = upyun_shop_img + tmp_data[i].banner+'?a='+Math.random();
				}else{
					var tmp_img = base_img;
				}
				tmp_str += "<img src='Public/Image/base.png' srcs='"+tmp_img+"' style='width:100px;height:100px;float:left;border:5px solid #eaa' alt=''>";
				tmp_str += "登陆账号："+tmp_data[i].account+"<br>商户名称："+ChangeChar(tmp_data[i].name,2)+"<br>创建时间："+tmp_data[i].ctime+"<br>商户地址："+ChangeChar(tmp_data[i].addr,3)+"<br>商户描述："+ChangeChar(tmp_data[i].info,2);
				switch(tmp_data[i].stat){
					case '1':var stat_str2 = '<span style="color:#fff">待审</span>';

					break;
					case '2':var stat_str2 = '<span style="color:#00f">正常</span>';break;
					case '3':var stat_str2 = '<span style="color:#ff0">未通过</span>';break;
					case '4':var stat_str2 = '<span style="color:#f00">已封禁</span>';break;
				}
				tmp_str +="<div style='text-align:right'>状态："+stat_str2+"　<button onclick=MainStore_ChangeStat('"+tmp_data[i].account+"',2)>通过</button><button onclick=MainStore_ChangeStat('"+tmp_data[i].account+"',3)>未通过</button><button onclick=MainStore_ChangeStat('"+tmp_data[i].account+"',4)>封禁</button><button onclick=MainStore_ChangeStat('"+tmp_data[i].account+"',1)>解封</button>　<button onclick='MainStore_CatGoodsList("+tmp_data[i].id+")'>商品列表</button></div>";
				tmp_str += "</div>";
			}
			$('#MainStore_StoreList').html(tmp_str);
			Img_Later_View3('#MainStore_StoreList','srcs');	//图片懒加载
			Fpage(sessionStorage.MainStore_Pnow,sessionStorage.MainStore_MaxPage,function(p){
				sessionStorage.MainStore_Pnow = p;
				sessionStorage.MainStore_MaxPage = p + 1;
				MainStore_GetAndView();
			},1,1,'#AdminStoreContorl_Fpage');
		}else{
			if(sessionStorage.MainStore_Pnow == 1){
				$('#MainGoods_GoodsList').html('<h2 style="text-align:center;color:red">暂无数据</h2>');
				Fpage(1,1,function(p){
					
				},1,1,'#AdminStoreContorl_Fpage');
			}else{
				sessionStorage.MainStore_Pnow = sessionStorage.MainStore_Pnow>2?sessionStorage.MainStore_Pnow-1:1;
				sessionStorage.MainStore_MaxPage = sessionStorage.MainStore_Pnow;
				MainStore_GetAndView();

			}
		}
	}







	//分页
	function Fpage_Ext(){
		if(sessionStorage.MainStore_MaxPage){
			var max_page = sessionStorage.MainStore_MaxPage;
		}else{
			var max_page = parseInt(sessionStorage.MainStore_Pnow)+1;
		}
		Fpage(sessionStorage.MainStore_Pnow,max_page,function(pnow){
			sessionStorage.MainStore_Pnow = pnow;
			MainStore_GetAndView();
		},2,2,'#AdminStoreContorl_Fpage');
	}



	//更改商户状态
	function MainStore_ChangeStat(store_account,store_stat){
		if(!confirm('确认更改状态?')){
			return;
		}
		if(!store_account || !store_stat){
			return;
		}
		var data = {
			type:'MainStore_ChangeStat',
			store_account:store_account,
			store_stat:store_stat
		};
		AjaxAdmin(data,function(res){
			var tmp = _checkJsonFormat(res);
			if(tmp.stat == 'ok'){
				A('操作成功！');
				$('#MainStore_StoreList').html('');
				MainStore_GetAndView();
			}else{
				A('操作失败!');
			}
		});
	}
	







	//查看商户下的商品列表 
	function MainStore_CatGoodsList(sid){
		sessionStorage.StoreToGoods_StoreId = sid;	//商户跳商品列表时的商户id
		$('#Main_Nav').val('Main_Goods');
		_loadPage();
	}









	//重置本页相关数据
	function _MainStore_Reset(){
		sessionStorage.MainStore_Pnow = 1;
		sessionStorage.MainStore_MaxPage = 2;
	}
</script>